package com.handpay.zztong.hp.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.bean.BankArea;
import com.handpay.zztong.hp.log.HPLog;

public class AreaAdapter extends BaseAdapter {


	List<BankArea> mBankArea = new ArrayList<BankArea>(100);
	LayoutInflater mLI = null;
	Context hpcontext;
	public AreaAdapter(Context context) {
		mLI = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		hpcontext = context;
	}
	
	public synchronized void refreshBankArea(List<BankArea> bankArea) {
		mBankArea.clear();
		mBankArea.addAll(bankArea);
		this.notifyDataSetChanged();
	}
	public synchronized void clearBankAreas() {
		mBankArea.clear();
	}
	@Override
	public int getCount() {
		return mBankArea.size();
	}

	@Override
	public Object getItem(int position) {
		return mBankArea.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	// 用于其他
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View container = null;
		if(null == convertView) {
			convertView = mLI.inflate(R.layout.bank_item, null);
		}
        HPLog.i("BankProvinceAdapter","getView:" + position);
		container = convertView;
		container.findViewById(R.id.ivBankLogo).setVisibility(View.GONE);
		((TextView)container.findViewById(R.id.tvBankName)).setText(mBankArea.get(position).getBankAreaName());
		container.findViewById(R.id.ivChecked).setVisibility(View.GONE);
		return container;
	}
    // 用于spinner
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		View container = null;
		if(null == convertView) {
			convertView = mLI.inflate(R.layout.bank_item, null);
		}
		container = convertView;
		container.findViewById(R.id.ivBankLogo).setVisibility(View.GONE);
		TextView tvbankname = (TextView)container.findViewById(R.id.tvBankName);
		tvbankname.setText(mBankArea.get(position).getBankAreaName());
		tvbankname.setTextColor(hpcontext.getResources().getColorStateList(R.color.keyboardnumber));
		container.findViewById(R.id.ivChecked).setVisibility(View.GONE);
		return container;
	}


}
